<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Template test cases</title>
<link rel="stylesheet" href="../../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Boost.Test">
<link rel="up" href="../test_cases.html" title="Test cases">
<link rel="prev" href="test_case_generation/generators.html" title="Datasets generators">
<link rel="next" href="param_test.html" title="Parametrized test cases">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="test_case_generation/generators.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../test_cases.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="param_test.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_test.tests_organization.test_cases.test_organization_templates"></a><a class="link" href="test_organization_templates.html" title="Template test cases">Template
        test cases</a>
</h4></div></div></div>
<p>
          In order to test a template based component, it is frequently necessary
          to perform the same set of checks for a component instantiated with different
          template parameters.
        </p>
<p>
          One way to perform the same set of checks for a component instantiated
          with different template parameters would be:
        </p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">single_test</span><span class="special">()</span>
<span class="special">{</span>
  <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="comment">/* test assertion */</span> <span class="special">);</span>
<span class="special">}</span>

<span class="keyword">void</span> <span class="identifier">combined_test</span><span class="special">()</span>
<span class="special">{</span>
  <span class="identifier">single_test</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;();</span>
  <span class="identifier">single_test</span><span class="special">&lt;</span><span class="keyword">float</span><span class="special">&gt;();</span>
  <span class="identifier">single_test</span><span class="special">&lt;</span><span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">&gt;();</span>
<span class="special">}</span>
</pre>
<p>
          There several problems/inconveniences with above approach, including:
        </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              Fatal error in one of the invocation will stop whole test case and
              will skip invocations with different types
            </li>
<li class="listitem">
              You need to repeat function invocation manually for all the parameters
              you are interested in
            </li>
<li class="listitem">
              You need two functions to implement the test
            </li>
</ul></div>
<p>
          The <span class="emphasis"><em>Unit Test Framework</em></span> provides a facility, the
          <span class="bold"><strong>template test case</strong></span>, to create a series
          of test cases based on a list of desired types and <span class="emphasis"><em>nullary</em></span>
          function. This facility comes with an <a class="link" href="test_organization_templates.html#ref_BOOST_AUTO_TEST_CASE_TEMPLATE">automatic</a>
          and <a class="link" href="test_organization_templates.html#ref_BOOST_TEST_CASE_TEMPLATE">manual</a> registration
          interface.
        </p>
<div class="tip"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../../../doc/src/images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>
            The test case template facility is preferable to the approach in example
            above, since execution of each sub test case is guarded and counted separately.
            It produces a better test log/results report (in example above in case
            of failure you can't say which type is at fault) and allows you to test
            all types even if one of them causes termination of the sub test case.
          </p></td></tr>
</table></div>
<a name="ref_BOOST_AUTO_TEST_CASE_TEMPLATE"></a><h5>
<a name="boost_test.tests_organization.test_cases.test_organization_templates.h0"></a>
          <span class="phrase"><a name="boost_test.tests_organization.test_cases.test_organization_templates.template_test_case_with_automate"></a></span><a class="link" href="test_organization_templates.html#boost_test.tests_organization.test_cases.test_organization_templates.template_test_case_with_automate">Template
          test case with automated registration</a>
        </h5>
<p>
          A template test case, registered automatically and in place of its implementation,
          is declared through the macro <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_auto_template.html" title="BOOST_AUTO_TEST_CASE_TEMPLATE"><code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span></code></a>:
        </p>
<pre class="programlisting"><span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span><span class="special">(</span><span class="identifier">test_case_name</span><span class="special">,</span> <span class="identifier">formal_type_parameter_name</span><span class="special">,</span> <span class="identifier">collection_of_types</span><span class="special">);</span>
</pre>
<p>
          The arguments are as follow:
        </p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
              <code class="computeroutput"><span class="identifier">test_case_name</span></code>: the
              test case template name: unique test cases template identifier
            </li>
<li class="listitem">
              <code class="computeroutput"><span class="identifier">formal_type_parameter_name</span></code>:
              the name of a formal template parameter: name of the type the test
              case template is instantiated with
            </li>
<li class="listitem">
              <code class="computeroutput"><span class="identifier">collection_of_types</span></code>:
              the collection of types to instantiate test case template with. This
              is an <span class="bold"><strong>arbitrary MPL sequence</strong></span> or a
              sequence of types wrapped in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span></code>
              (since <a class="link" href="../../change_log.html#ref_CHANGE_LOG_3_7"><span class="emphasis"><em>Unit Test Framework</em></span>
              v3.7</a>, if supported by the compiler)
            </li>
</ol></div>
<p>
          The resulting name of the test is a composition of the <code class="computeroutput"><span class="identifier">test_case_name</span></code>
          parameter and the current type being tested. Since <a class="link" href="../../change_log.html#ref_CHANGE_LOG_3_12"><span class="emphasis"><em>Unit
          Test Framework</em></span> v3.12</a>, the framework tries to unify the
          name of the resulting type across various platforms such that they are
          easier to reference from the <a class="link" href="../../runtime_config/test_unit_filtering.html" title="Test unit filtering">command
          line filter</a>.
        </p>
<h6>
<a name="boost_test.tests_organization.test_cases.test_organization_templates.h1"></a>
          <span class="phrase"><a name="boost_test.tests_organization.test_cases.test_organization_templates.example_descr"></a></span><a class="link" href="test_organization_templates.html#boost_test.tests_organization.test_cases.test_organization_templates.example_descr">Example:
          Test case template with automated registration</a>
        </h6>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                  <p>
                    Code
                  </p>
                </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">example</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mpl</span><span class="special">/</span><span class="identifier">list</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="keyword">long</span><span class="special">,</span><span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">&gt;</span> <span class="identifier">test_types</span><span class="special">;</span>

<span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span><span class="special">(</span> <span class="identifier">my_test</span><span class="special">,</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">test_types</span> <span class="special">)</span>
<span class="special">{</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">==</span> <span class="special">(</span><span class="keyword">unsigned</span><span class="special">)</span><span class="number">4</span> <span class="special">);</span>
<span class="special">}</span>

<span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">long</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">&gt;</span> <span class="identifier">test_types_w_tuples</span><span class="special">;</span>

<span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span><span class="special">(</span> <span class="identifier">my_tuple_test</span><span class="special">,</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">test_types_w_tuples</span> <span class="special">)</span>
<span class="special">{</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">==</span> <span class="special">(</span><span class="keyword">unsigned</span><span class="special">)</span><span class="number">4</span> <span class="special">);</span>
<span class="special">}</span>
</pre>
                </td></tr></tbody>
</table></div>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                  <p>
                    Output
                  </p>
                </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="identifier">example</span>
<span class="identifier">Running</span> <span class="number">3</span> <span class="identifier">test</span> <span class="identifier">cases</span><span class="special">...</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">17</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"my_test&lt;unsigned char&gt;"</span><span class="special">:</span> <span class="identifier">check</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">==</span> <span class="special">(</span><span class="keyword">unsigned</span><span class="special">)</span><span class="number">4</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">1</span> <span class="special">!=</span> <span class="number">4</span><span class="special">]</span>

<span class="special">***</span> <span class="number">1</span> <span class="identifier">failure</span> <span class="identifier">is</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">the</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"example"</span>
</pre>
                </td></tr></tbody>
</table></div>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>
            Since <a class="link" href="../../change_log.html#ref_CHANGE_LOG_3_7"><span class="emphasis"><em>Unit Test Framework</em></span>
            v3.7</a>, the <span class="emphasis"><em>Unit Test Framework</em></span> does not allow
            for duplicate test case name under the same test suite. As test names
            are derived from the types in the <code class="computeroutput"><span class="identifier">collection_of_types</span></code>,
            this indirectly means that <span class="bold"><strong>having a duplicate type</strong></span>
            in the <code class="computeroutput"><span class="identifier">collection_of_types</span></code>
            <span class="bold"><strong>yields an error</strong></span>.
          </p></td></tr>
</table></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
<p>
            If you prefer having the template parameter list directly in the declaration
            of <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_auto_template.html" title="BOOST_AUTO_TEST_CASE_TEMPLATE"><code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span></code></a>,
            you may use the macro <a href="../../../www.boost.org/doc/libs/release/libs/utility/identity_type/doc/html/index.html" target="_top"><code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span></code></a>. The previous
            example gives (note the double parenthesis around the MPL list):
          </p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">identity_type</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span><span class="special">(</span>
  <span class="identifier">my_test</span><span class="special">,</span>
  <span class="identifier">T</span><span class="special">,</span>
  <span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span>
    <span class="keyword">int</span><span class="special">,</span>
    <span class="keyword">long</span><span class="special">,</span>
    <span class="keyword">unsigned</span> <span class="keyword">char</span>
  <span class="special">&gt;))</span> <span class="special">)</span>
<span class="special">{</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">==</span> <span class="special">(</span><span class="keyword">unsigned</span><span class="special">)</span><span class="number">4</span> <span class="special">);</span>
<span class="special">}</span>
</pre>
</td></tr>
</table></div>
<a name="ref_BOOST_TEST_CASE_TEMPLATE"></a><h5>
<a name="boost_test.tests_organization.test_cases.test_organization_templates.h2"></a>
          <span class="phrase"><a name="boost_test.tests_organization.test_cases.test_organization_templates.test_case_template_with_manual_r"></a></span><a class="link" href="test_organization_templates.html#boost_test.tests_organization.test_cases.test_organization_templates.test_case_template_with_manual_r">Test
          case template with manual registration</a>
        </h5>
<p>
          To manually register template test cases, two macros should be used:
        </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template_function.html" title="BOOST_TEST_CASE_TEMPLATE_FUNCTION"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span></code></a>
              to define the template test case body
            </li>
<li class="listitem">
              <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template.html" title="BOOST_TEST_CASE_TEMPLATE"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE</span></code></a> to
              register the test case based on the previous declaration
            </li>
</ul></div>
<p>
          The macro <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template_function.html" title="BOOST_TEST_CASE_TEMPLATE_FUNCTION"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span></code></a>
          requires two arguments:
        </p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
              the name of the test case template and
            </li>
<li class="listitem">
              the name of the format type parameter
            </li>
</ol></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span><span class="special">(</span><span class="identifier">test_case_name</span><span class="special">,</span> <span class="identifier">type_name</span><span class="special">);</span>
</pre>
<pre class="programlisting"><span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span><span class="special">(</span> <span class="identifier">test_case_name</span><span class="special">,</span> <span class="identifier">type_name</span> <span class="special">)</span>
<span class="special">{</span>
  <span class="comment">// test case template body</span>
<span class="special">}</span>
</pre>
<p>
          The macro <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template_function.html" title="BOOST_TEST_CASE_TEMPLATE_FUNCTION"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span></code></a>
          is intended to be used in place of nullary function template signature:
        </p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">type_name</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">test_case_name</span><span class="special">()</span>
<span class="special">{</span>
  <span class="comment">// test case template body</span>
<span class="special">}</span>
</pre>
<p>
          The only difference is that the <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template_function.html" title="BOOST_TEST_CASE_TEMPLATE_FUNCTION"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span></code></a>
          makes the test case template name usable in the template argument list.
        </p>
<p>
          <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template.html" title="BOOST_TEST_CASE_TEMPLATE"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE</span></code></a> requires
          two arguments:
        </p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
              the name of the test case template and
            </li>
<li class="listitem">
              Boost.MPL compatible collection of types to instantiate it with.
            </li>
</ol></div>
<p>
          The names passed to both macros should be the same.
        </p>
<pre class="programlisting"><span class="identifier">BOOST_TEST_CASE_TEMPLATE</span><span class="special">(</span><span class="identifier">test_case_name</span><span class="special">,</span> <span class="identifier">collection_of_types</span><span class="special">);</span>
</pre>
<h6>
<a name="boost_test.tests_organization.test_cases.test_organization_templates.h3"></a>
          <span class="phrase"><a name="boost_test.tests_organization.test_cases.test_organization_templates.example_descr0"></a></span><a class="link" href="test_organization_templates.html#boost_test.tests_organization.test_cases.test_organization_templates.example_descr0">Example:
          Manually registered test case template</a>
        </h6>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                  <p>
                    Code
                  </p>
                </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mpl</span><span class="special">/</span><span class="identifier">list</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">;</span>

<span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span><span class="special">(</span> <span class="identifier">my_test</span><span class="special">,</span> <span class="identifier">T</span> <span class="special">)</span>
<span class="special">{</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">==</span> <span class="number">4U</span> <span class="special">);</span>
<span class="special">}</span>

<span class="identifier">test_suite</span><span class="special">*</span> <span class="identifier">init_unit_test_suite</span><span class="special">(</span> <span class="keyword">int</span> <span class="comment">/*argc*/</span><span class="special">,</span> <span class="keyword">char</span><span class="special">*</span> <span class="comment">/*argv*/</span><span class="special">[]</span> <span class="special">)</span>
<span class="special">{</span>
  <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="keyword">long</span><span class="special">,</span><span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">&gt;</span> <span class="identifier">test_types</span><span class="special">;</span>

  <span class="identifier">framework</span><span class="special">::</span><span class="identifier">master_test_suite</span><span class="special">().</span>
    <span class="identifier">add</span><span class="special">(</span> <span class="identifier">BOOST_TEST_CASE_TEMPLATE</span><span class="special">(</span> <span class="identifier">my_test</span><span class="special">,</span> <span class="identifier">test_types</span> <span class="special">)</span> <span class="special">);</span>

  <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
</pre>
                </td></tr></tbody>
</table></div>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                  <p>
                    Output
                  </p>
                </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="identifier">example</span>
<span class="identifier">Running</span> <span class="number">3</span> <span class="identifier">test</span> <span class="identifier">cases</span><span class="special">...</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">15</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"my_test&lt;unsigned char&gt;"</span><span class="special">:</span> <span class="identifier">check</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">==</span> <span class="number">4U</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">1</span> <span class="special">!=</span> <span class="number">4</span><span class="special">]</span>

<span class="special">***</span> <span class="number">1</span> <span class="identifier">failure</span> <span class="identifier">is</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">the</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"Master Test Suite"</span>
</pre>
                </td></tr></tbody>
</table></div>
<p>
          <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template.html" title="BOOST_TEST_CASE_TEMPLATE"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE</span></code></a> creates
          an instance of the test case generator. When passed to the method <code class="computeroutput"><a class="link" href="../../../boost/unit_test/test_suite.html#idm44970733617744-bb">test_suite::add</a></code>,
          the generator produces a separate sub test case for each type in the supplied
          collection of types and registers it immediately in the test suite. Each
          test case is based on the test case template body instantiated with a particular
          test type.
        </p>
<p>
          The names for the <span class="emphasis"><em>sub test cases</em></span> are deduced from
          the macro argument <code class="computeroutput"><span class="identifier">test_case_name</span></code>.
          If you prefer to assign different test case names, you need to use the
          underlying <code class="computeroutput"><a class="link" href="../../../header/boost/test/tree/test_unit_hpp.html" title="Header &lt;boost/test/tree/test_unit.hpp&gt;">make_test_case</a></code> interface
          instead. Both test cases creation and registration is performed in the
          test module initialization function.
        </p>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>
            Since <a class="link" href="../../change_log.html#ref_CHANGE_LOG_3_7"><span class="emphasis"><em>Unit Test Framework</em></span>
            v3.7</a>, the <span class="emphasis"><em>Unit Test Framework</em></span> does not allow
            for duplicate test case name under the same test suite. As test names
            are derived from the types in the <code class="computeroutput"><span class="identifier">collection_of_types</span></code>,
            this indirectly means that having a duplicate of types in the <code class="computeroutput"><span class="identifier">collection_of_types</span></code> will yield an error.
          </p></td></tr>
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001-2020 Boost.Test contributors<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="test_case_generation/generators.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../test_cases.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="param_test.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
